<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Admin\Role;
use App\Models\Admin\Auth;
class RoleController extends Controller
{
    //
    public function index(){

    	$data = Role::get();

    	return view('admin/role/index',compact('data'));
    }
    public function assign(Request $request){

    	if($request->isMethod('post')){

    		$data = $request->only(['id','auth_id']);
            // var_dump($data);

            $role = new Role();
            
            $result = $role -> assignAuth($data);

            return $result;
    	}else{
    		$top = Auth::where('pid','0',)->get();
    		$cat = Auth::where('pid','!=','0')->get();
            $ids = Role::where('id',$request->only('id')) ->value('auth_ids');
           


    		return view('admin/role/assign',compact('top','cat','ids'));
    	}

    	
    }
}
